package com.shiqi.bio.broadcast;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

/**
 * @author shiqi
 * @version 1.0.0
 * @ClassName Server.java
 * @Description
 * @createTime 2022-05-16
 */
public class Server {
    public static List<Socket> allSocketOnLine = new ArrayList<>();

    public static void main(String[] args) {
        try {
            ServerSocket ss = new ServerSocket(9999);
            while (true) {
                //接受连接
                Socket socket = ss.accept();
                System.out.println(socket.getInetAddress().getHostAddress());
                //保存连接到 集合
                allSocketOnLine.add(socket);
                //为当前连接成功的socket分配一个独立的线程来处理与之通信
                new ServerReaderThread(socket).start();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

